package com.kld.yqyj.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.kld.common.annotation.RepeatSubmit;
import com.kld.common.annotation.Log;
import com.kld.common.core.controller.BaseController;
import com.kld.common.core.domain.PageQuery;
import com.kld.common.core.domain.R;
import com.kld.common.core.validate.AddGroup;
import com.kld.common.core.validate.EditGroup;
import com.kld.common.core.validate.QueryGroup;
import com.kld.common.enums.BusinessType;
import com.kld.common.utils.poi.ExcelUtil;
import com.kld.yqyj.domain.vo.TInjwwGroupVo;
import com.kld.yqyj.domain.bo.TInjwwGroupBo;
import com.kld.yqyj.service.ITInjwwGroupService;
import com.kld.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiOperation;

/**
 * 注水井中心井组关系Controller
 *
 * @author bw
 * @date 2024-05-15
 */
@Validated
@Api(value = "注水井中心井组关系控制器", tags = {"注水井中心井组关系管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/yqyj/injwwGroup")
public class TInjwwGroupController extends BaseController {

    private final ITInjwwGroupService iTInjwwGroupService;

    /**
     * 查询注水井中心井组关系列表
     */
    @ApiOperation("查询注水井中心井组关系列表")
    @SaCheckPermission("yqyj:injwwGroup:list")
    @GetMapping("/list")
    public TableDataInfo<TInjwwGroupVo> list(@Validated(QueryGroup.class) TInjwwGroupBo bo, PageQuery pageQuery) {
        return iTInjwwGroupService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出注水井中心井组关系列表
     */
    @ApiOperation("导出注水井中心井组关系列表")
    @SaCheckPermission("yqyj:injwwGroup:export")
    @Log(title = "注水井中心井组关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@Validated TInjwwGroupBo bo, HttpServletResponse response) {
        List<TInjwwGroupVo> list = iTInjwwGroupService.queryList(bo);
        ExcelUtil.exportExcel(list, "注水井中心井组关系", TInjwwGroupVo.class, response);
    }

    /**
     * 获取注水井中心井组关系详细信息
     */
    @ApiOperation("获取注水井中心井组关系详细信息")
    @SaCheckPermission("yqyj:injwwGroup:query")
    @GetMapping("/{injmcId}")
    public R<TInjwwGroupVo> getInfo(@ApiParam("主键")
                                                  @NotNull(message = "主键不能为空")
                                                  @PathVariable("injmcId") String injmcId) {
        return R.ok(iTInjwwGroupService.queryById(injmcId));
    }

    /**
     * 新增注水井中心井组关系
     */
    @ApiOperation("新增注水井中心井组关系")
    @SaCheckPermission("yqyj:injwwGroup:add")
    @Log(title = "注水井中心井组关系", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TInjwwGroupBo bo) {
        return toAjax(iTInjwwGroupService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改注水井中心井组关系
     */
    @ApiOperation("修改注水井中心井组关系")
    @SaCheckPermission("yqyj:injwwGroup:edit")
    @Log(title = "注水井中心井组关系", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TInjwwGroupBo bo) {
        return toAjax(iTInjwwGroupService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除注水井中心井组关系
     */
    @ApiOperation("删除注水井中心井组关系")
    @SaCheckPermission("yqyj:injwwGroup:remove")
    @Log(title = "注水井中心井组关系", businessType = BusinessType.DELETE)
    @DeleteMapping("/{injmcIds}")
    public R<Void> remove(@ApiParam("主键串")
                                       @NotEmpty(message = "主键不能为空")
                                       @PathVariable String[] injmcIds) {
        return toAjax(iTInjwwGroupService.deleteWithValidByIds(Arrays.asList(injmcIds), true) ? 1 : 0);
    }
}
